﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SHJunketingBLL;
using SHJunketingModel;
using Web;
using System.Data;

public partial class Admin_UserManagement_AppointmentEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["userId"] != null)
            {
                int userId = Convert.ToInt32(Request.QueryString["userId"].ToString());
                Session["users"] = userId;
                //查询出用户
                string sql = "select * from users where userid = " + userId;

                DataTable table = DBHelper.GetDataSet(sql);

                if (table.Rows.Count > 0)
                {
                    Label1.Text = table.Rows[0]["userlogin"].ToString();
                    Label2.Text = table.Rows[0]["UserName"].ToString();
                    Label3.Text = table.Rows[0]["UserSex"].ToString();
                    Label4.Text = table.Rows[0]["Department"].ToString();
                    Label5.Text = table.Rows[0]["CostCenters"].ToString();
                    Label6.Text = table.Rows[0]["UserIDCard"].ToString();
                    Label7.Text = table.Rows[0]["UserAge"].ToString();
                    Label8.Text = table.Rows[0]["Marriage"].ToString();
                    Label9.Text = table.Rows[0]["HandsetNumber"].ToString();
                    Label10.Text = table.Rows[0]["TelephoneNumber"].ToString();
                    Label11.Text = table.Rows[0]["UserAddress"].ToString();
                    Label12.Text = table.Rows[0]["UserEmail"].ToString();
                    Label13.Text = table.Rows[0]["Area"].ToString();
                    Label14.Text = table.Rows[0]["language"].ToString();

                    ViewState["userId"] = table.Rows[0]["UserId"];

                }


                //判断用户现在的体检状态
                GetAppointment();
                GetApp();
            }
        }
    }
    //预约体检(静安)
    protected void btnEbit_Click(object sender, EventArgs e)
    {
        Response.Redirect("AppointmentJ.aspx?userId = '" + Session["users"] + "'");
    }
    //预约体检(陆家嘴)
    protected void btnEbit0_Click(object sender, EventArgs e)
    {
        Response.Redirect("AppointmentL.aspx?userId = '" + Session["users"] + "'");
    }
    //取消体检
    protected void btnquxiao_Click(object sender, EventArgs e)
    {
        string sql = "update MedicalAppointment set bookingstatus =1 where userid = '" + ViewState["userId"] + "'";
        int result = DBHelper.ExecuteCommand(sql);
        if (result > 0)
        {
            Web.CommFun.Show_Msg("已经成功取消体检！", "userManage.aspx");
        }
        else 
        {
            Web.CommFun.Show_Msg("取消体检失败！");
        }
    }
    //已体检
    protected void btnYi_Click(object sender, EventArgs e)
    {
        string sql = "update MedicalAppointment set bookingstatus =2 where userid = '" + ViewState["userId"] + "'";
        int result = DBHelper.ExecuteCommand(sql);
        if (result > 0)
        {
            Web.CommFun.Show_Msg("已经成功体检！", "userManage.aspx");
        }
        else
        {
            Web.CommFun.Show_Msg("体检失败！");
        }
    }

    //判断用户现在的体检状态
    public void GetAppointment() 
    {
        string sql1 = "select * from MedicalAppointment where UserID ='" + ViewState["userId"] + "'";
        DataTable table1 = DBHelper.GetDataSet(sql1);
        if (table1.Rows.Count > 0) //有预约体检
        {
            string BookingStatus = table1.Rows[0]["BookingStatus"].ToString();
            if (BookingStatus.Equals("0"))
            {
                this.btnquxiao.Visible = true;
                this.btnYi.Visible = true;
            }
            else if (BookingStatus.Equals("1"))
            {
                this.btnEbit.Visible = true;
                this.btnEbit0.Visible = true;
            }
        }
        else
        {
            this.btnEbit.Visible = true;
            this.btnEbit0.Visible = true;
        }
    }

    public void GetApp() 
    {
        string sql1 = "select * from MedicalAppointment where UserID ='" + ViewState["userId"] + "'";
        DataTable table1 = DBHelper.GetDataSet(sql1);
        if (table1.Rows.Count > 0) //有预约体检
        {
            DateTime time = DateTime.Parse(table1.Rows[0]["ReservationTime"].ToString());
            string BookingStatus = table1.Rows[0]["BookingStatus"].ToString();
            if (BookingStatus.Equals("0"))
            {
                Label15.Text = "已预约";
            }
            else if (BookingStatus.Equals("1"))
            {
                Label15.Text = "已取消";
            }
            else
            {
                Label15.Text = "已体检";
            }

            this.Label23.Text = time.ToString("yyyy-MM-dd");
            this.Label22.Text = table1.Rows[0]["AgencyName"].ToString();
        }
    }
    
}
